package com.ht.medicaltreatment.viewmodel

import com.hjq.http.EasyHttp
import com.hjq.http.listener.OnHttpListener
import com.ht.medicaltreatment.bean.ProjectConsumable
import com.ht.medicaltreatment.bean.ShenQingBean
import com.ht.medicaltreatment.bean.SuccessBean
import com.ht.medicaltreatment.http.api.ShenQingAPI
import com.ht.medicaltreatment.http.api.ShenQingSubmitAPI

class ShenQingViewModel : BaseViewModel(){
    fun getList(id:String,onResult:(MutableList<ProjectConsumable>)->Unit){
        EasyHttp.post(this)
            .api(ShenQingAPI(id))
            .request(object : OnHttpListener<ShenQingBean>{
                override fun onHttpSuccess(result: ShenQingBean) {
                    //onResult(result.data.projectConsumableList)
                }

                override fun onHttpFail(e: Exception) {
                    dismissProgress(e.message?:"")
                }
            })
    }

    fun submit(api:ShenQingSubmitAPI,onResult:()->Unit){
        EasyHttp.post(this)
            .api(api)
            .request(object : OnHttpListener<SuccessBean>{
                override fun onHttpSuccess(result: SuccessBean) {
                    if(result.code == 200){
                        onResult()
                    }else{
                        dismissProgress(result.message)
                    }
                }

                override fun onHttpFail(e: Exception) {
                    dismissProgress(e.message?:"")
                }
            })
    }
}
